const express = require('express')
const path = require('path')
const app = express()
// 想像这是一个非nodejs
//https://vitejs.cn/guide/backend-integration.html
const manifest = require('./dist/manifest.json') // 引入vite build之后的配置

app.engine('pug', require('pug').__express) //注册模板引擎的 callback 用来处理ext扩展名的文件
app.set('views', path.join(__dirname, 'views')) //路径
app.set('view engine', 'pug')

app.use(express.static(path.join(__dirname, 'dist'))) // link和script引入完后要部署dist的静态资源

app.get('/vite_threeServer', (req, res) => {
  res.render('index', {
    title: 'hey',
    message: 'hello message',
    index: manifest['index.html'].file,
    // vendor: manifest['index.html'].dynamicImports,
    css: manifest['index.html'].css[0],
  })
})

app.listen(4000, () => {
  console.log('listenning...', 4000)
})
